#include "StdAfx.h"
#include "CaelumEnv.h"
#include "Enviroment.h"
#include <Caelum.h>

#if _DEBUG
#pragma comment ( lib, "Caelum_d.lib" )
#else
#pragma comment ( lib, "Caelum.lib" )
#endif

IMPLEMENT_Singleton(VWD::CaelumEnv)

Caelum::CaelumSystem *pCaelumSystem = 0;

VWD::CaelumEnv::CaelumEnv(void)
{
	
}

VWD::CaelumEnv::~CaelumEnv(void)
{
	Shutdown();
}

void VWD::CaelumEnv::Init()
{
	if(pCaelumSystem==0)
	{
		pCaelumSystem = new Caelum::CaelumSystem(
			Ogre::Root::getSingletonPtr(),
			VWD::Enviroment::SceneManager,
			Caelum::CaelumSystem::CAELUM_COMPONENTS_DEFAULT);
		Ogre::Root::getSingletonPtr()->addFrameListener(pCaelumSystem);
		VWD::Enviroment::RenderWindow->addListener(pCaelumSystem);
		pCaelumSystem->setTimeScale(512);
		pCaelumSystem->setManageSceneFog(true);
		pCaelumSystem->setSceneFogDensityMultiplier(0.0025);		
		pCaelumSystem->setManageAmbientLight(true);
		pCaelumSystem->setMinimumAmbientLight(Ogre::ColourValue(0,0,0.5));
	}
}

void VWD::CaelumEnv::Shutdown()
{
	if(pCaelumSystem!=0)
	{
		VWD::Enviroment::RenderWindow->removeListener(pCaelumSystem);
		Ogre::Root::getSingletonPtr()->removeFrameListener(pCaelumSystem);
		pCaelumSystem->shutdown(true);
		pCaelumSystem = 0;
	}
}